package xhwl.insurance.dialog;

import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.Display;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.TextView;

import de.greenrobot.event.EventBus;
import xhwl.insurance.R;
import xhwl.insurance.event.LayoutChangeEvent;

/**
 * Created by fuyi on 2017/9/30.
 */

public class CallPhoneDialog extends Dialog implements View.OnClickListener {
    private Context context;

    private Window window;

    public CallPhoneDialog(Context context) {
        super(context, R.style.DialogRound);
        this.context = context;
        this.setContentView(R.layout.dialog_callphonedialog);

    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        window = getWindow();
        intView();
        initData();
    }

    private void intView() {
        WindowManager.LayoutParams attributes = window.getAttributes();
        attributes.gravity = Gravity.CENTER_HORIZONTAL | Gravity.CENTER_HORIZONTAL;
        window.setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT);
        WindowManager m = window.getWindowManager();
        Display d = m.getDefaultDisplay();
        WindowManager.LayoutParams p = getWindow().getAttributes();
        p.height = (int) (d.getHeight() * 0.205);
        p.width = (int) (d.getWidth() * 0.8);
//        p.alpha = 1.0f; // 设置本身透明度
//        p.dimAmount = 0.0f; // 设置黑暗度
        getWindow().setAttributes(p); // 设置生效
    }


    private void initData() {
        Button cancel = (Button) findViewById(R.id.tv_call_reconfirm);
        Button confirm = (Button) findViewById(R.id.tv_call_qudinge);
        cancel.setOnClickListener(this);
        confirm.setOnClickListener(this);

    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.tv_call_reconfirm:
                EventBus.getDefault().post(new LayoutChangeEvent());
                dismiss();
                break;
            case R.id.tv_call_qudinge:
                Uri data = Uri.parse("tel:" + "4006562020");
                Intent intent = new Intent(Intent.ACTION_DIAL, data);
                context.startActivity(intent);
                dismiss();
                break;

        }
    }
}
